home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / vol6n13.arc / MOUSEKEY.ASM < prev    next >
Assembly Source File  |  1987-07-03  |  6KB  |  130 lines

  1. ;MOUSEKEY.COM for the Microsoft Mouse - 1987 by Jeff Prosise
  2. ;
  3. bios_data     segment at 40h
  4.               org 1Ah
  5. buffer_head   dw ?                          ;pointer to keyboard buffer head
  6. buffer_tail   dw ?                          ;pointer to keyboard buffer tail
  7.               org 80h
  8. buffer_start  dw ?                          ;starting keyboard buffer address
  9. buffer_end    dw ?                          ;ending keyboard buffer address
  10. bios_data     ends
  11. ;
  12. code          segment para public 'code'
  13.               assume cs:code
  14.               org 100h
  15. begin:        jmp initialize                ;goto initialization code
  16. ;
  17. copyright          db 'Copyright 1987 Ziff-Davis Publishing Co.'
  18. author             db 'Written by Jeff Prosise'
  19. vcount             db 3                     ;vertical delay counter
  20. hflag              dw ?                     ;horizontal count sign flag
  21. vflag              dw ?                     ;vertical count sign flag
  22. keycode            db 4Dh,4Bh,50h,48h       ;keycodes for cursor keys
  23. ;
  24. ;------------------------------------------------------------------------------
  25. ;MOUSE subroutine is handed control by the mouse driver when either the mouse
  26. ;is moved or either button is pressed.
  27. ;------------------------------------------------------------------------------
  28. mouse         proc far
  29. ;
  30. ;Determine which event occurred and branch accordingly.
  31. ;
  32.               test ax,2                     ;was the left button pressed?
  33.               jnz pgup                      ;yes, then branch
  34.               test ax,8                     ;was the right button pressed?
  35.               jnz pgdn                      ;yes, then branch
  36. ;
  37. ;Move the cursor in the direction indicated by the most recent mouse move.
  38. ;
  39. mouse0:       mov ax,11                     ;function 11
  40.               int 51                        ;read mouse motion counters
  41.               mov hflag,0                   ;initialize sign flags
  42.               mov vflag,2
  43.               xor al,al                     ;zero AL for extended keycode
  44.               cmp cx,0                      ;horizontal count positive?
  45.               jge mouse1                    ;yes, then branch
  46.               inc hflag                     ;record negative condition
  47.               neg cx                        ;convert negative to positive
  48. mouse1:       cmp dx,0                      ;vertical count positive?
  49.               jge mouse2                    ;yes, then branch
  50.               inc vflag                     ;record negative condition
  51.               neg dx                        ;convert negative to positive
  52. mouse2:       mov bx,hflag                  ;assume motion was horizontal
  53.               cmp cx,dx                     ;was the assumption correct?
  54.               jae mouse3                    ;yes, then branch
  55.               mov bx,vflag                  ;no, then correct it
  56.               dec vcount                    ;decrement vertical delay count
  57.               jz mouse3                     ;continue if count is zero
  58.               ret                           ;exit if it's not
  59. mouse3:       mov vcount,3                  ;reset delay counter
  60.               mov ah,keycode[bx]            ;get keycode from table
  61.               jmp insert                    ;insert it into keyboard buffer
  62. ;
  63. ;The left button was pressed.  Load AX with the keycode for the PgUp key.
  64. ;
  65. pgup:         mov ax,4900h                  ;load keycode
  66.               jmp insert                    ;insert it into the keyboard buffer
  67. ;
  68. ;The right button was pressed.  Load AX with the keycode for PgDn.
  69. ;
  70. pgdn:         mov ax,5100h                  ;load keycode
  71. ;
  72. ;Insert the keycode in AX into the keyboard buffer.
  73. ;
  74. insert:       mov bx,bios_data              ;point DS to BIOS data area
  75.               mov ds,bx
  76.               assume ds:bios_data
  77.               cli                           ;disable interrupts
  78.               mov bx,buffer_tail            ;get buffer tail address
  79.               mov dx,bx                     ;transfer it to DX
  80.               add dx,2                      ;calculate next buffer position
  81.               cmp dx,buffer_end             ;did we overshoot the end?
  82.               jne insert1                   ;no, then continue
  83.               mov dx,buffer_start           ;yes, then wrap around
  84. insert1:      cmp dx,buffer_head            ;is the buffer full?
  85.               je insert2                    ;yes, then end now
  86.               mov [bx],ax                   ;insert the keycode
  87.               mov bx,dx                     ;advance the tail
  88.               mov buffer_tail,bx            ;record its new position
  89. insert2:      sti                           ;enable interrupts
  90.               assume ds:nothing
  91.               ret                           ;exit user-defined subroutine
  92. mouse         endp
  93. ;
  94. ;------------------------------------------------------------------------------
  95. ;INITIALIZE routine points the mouse driver to the user-defined subroutine,
  96. ;then leaves it resident in memory.
  97. ;------------------------------------------------------------------------------
  98. initialize    proc near
  99.               jmp init0                     ;skip transient data area
  100. ;
  101. errmsg        db 13,10,'Mouse Not Installed',13,10,'$'
  102. ;
  103. ;Make sure the mouse hardware and software are in place.
  104. ;
  105. init0:        mov ax,0                      ;function 0
  106.               int 51                        ;get installation flag
  107.               or ax,ax                      ;is AX zero?
  108.               jne init1                     ;no, then installation OK
  109.               mov ah,9                      ;print error message and abort
  110.               lea dx,errmsg
  111.               int 21h
  112.               ret
  113. ;
  114. ;Point the mouse driver to the user-defined subroutine that will be executed
  115. ;anytime the mouse is moved or a button is pressed.
  116. ;
  117. init1:        mov ax,12                     ;function 12
  118.               mov cx,11                     ;subroutine call mask
  119.               mov dx,offset mouse           ;point ES:DX to subroutine
  120.               int 51                        ;pass information to mouse driver
  121. ;
  122. ;Terminate but leave the user-defined subroutine resident in memory.
  123. ;
  124.               lea dx,initialize             ;point DX to end of resident code
  125.               int 27h                       ;terminate-but-stay-resident
  126. initialize    endp
  127. ;
  128. code          ends
  129.               end begin
  130.